 const path = require('path');
 const CleanWebpackPlugin = require('clean-webpack-plugin');
 const HtmlWebpackPlugin = require('html-webpack-plugin');
 const VueLoaderPlugin = require('vue-loader/lib/plugin');
 const miniCssExtractPlugin = require('mini-css-extract-plugin');

   module.exports = {
       entry: {
         index: './src/main/entrise/index.js',
       },
       output: {
           filename: '[name].[contenthash].js',
           path: path.resolve(__dirname, 'dist'),
       },
   plugins: [
    //    new CleanWebpackPlugin(['dist']),
       new HtmlWebpackPlugin({
           template: 'src/main/entrise/template.ejs', // 源模板文件
           title: '资产库查询系统',
           minify: {
               removeAttributeQuotes: true,
               collapseWhitespace: true,
               html5: true,
               minifyCSS: true,
               removeComments: true,
               removeEmptyAttributes: true
           },
       }),
       new miniCssExtractPlugin({
           /*filename: "[name].[chunkhash:8].css",*/
           filename: 'style/[name].[contenthash].js',
           chunkFilename: "style/[name].css"
       }),
       new VueLoaderPlugin()
   ],
     optimization: {      /*代码分离,模板提取*/
          runtimeChunk: {
              name: entrypoint => `runtime~${entrypoint.name}`
          },
          splitChunks: {
            chunks: 'all',
            cacheGroups: {
                  vendor: {
                        test: /[\\/]node_modules[\\/]/,
                            name: 'vendors',
                            chunks: 'all'
                      },
/*                styles: {
                    name: 'css/styles',
                    test: /\.css$/,
                    chunks: 'all',
                    enforce: true
                }*/
                }
          }
     },
     module: {
         rules: [
             {
                 test: /\.(png|svg|jpg|gif)$/,
                 loader: 'file-loader',
                 options: {
                     name: 'static/img/[name].[ext]',
                     publicPath:'../'
                 },
            },
            {
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                loader: 'file-loader',
                options: {
                    name: 'static/fonts/[name].[ext]',
                    publicPath:'../'
                },
            },
            // {
            //       test: /\.(csv|tsv)$/,
            //       use: [
            //         'csv-loader'
            //       ]
            // },
            // {
            //   test: /\.xml$/,
            //       use: [
            //         'xml-loader'
            //       ]
            // },
           {
               test: /\.vue$/,
                   loader: 'vue-loader',
                   options: {
                       extractCSS: true
                   }
           },
             {
                 test: /\.less$/,
                 use: [
                     'vue-style-loader',
                     'css-loader',
                     'less-loader'
                 ]
             },
             {
                 test: /\.jsx?$/,
                 loader: "babel-loader",
                 exclude: /node_modules/,
                 options: {
                     presets: [['es2015', { loose: true }]],
                     cacheDirectory: true,
                     plugins: ['transform-runtime'],
                 },
             },
/*             {
                 test: /\.css$/,
                 use: [
                     'vue-style-loader',
                     {
                         loader: 'css-loader',
                         options: {
                             // 开启 CSS Modules
                             modules: true,
                             // 自定义生成的类名
                             localIdentName: '[local]_[hash:base64:8]',
                             publicPath :"../"
                         }
                     }
                 ]
             },*/
             {
                 test: /\.css$/,
                 use: [
                     miniCssExtractPlugin.loader,
                     "css-loader"
                 ]
             },
             {
                 test: /\.scss$/,
                 use: [ 'style-loader', 'css-loader', 'sass-loader' ]
             }
         ]
     }
 };